{extend name="public/base"/}
{block name="style"}
<link rel="stylesheet" href="__PUBLIC__/css/order.css">
<style>
    #order-more-btn {top: 30px;line-height: 30px;}
    #order-more-btn button { width: 100%;}
</style>
{/block}
{block name="content"}
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 Order">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab">
                        <div class="layui-tab-content">
                            <div class="layui-tab-item screen-box">
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">平台</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="platform_name="><a class="active">全部</a></li>
                                            {foreach name="platform" id="p"}
                                                <li item="platform_name={$p->name}"><a>{$p->name}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                {php}if(!isset($other_filter)):{/php}
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">订单状态</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="order_status="><a class="active">全部</a></li>
                                            {foreach name="order_status" id="p" key="k"}
                                                <li item="order_status={$k}"><a>{$p}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                {php}endif;{/php}
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">发货状态</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="send_status="><a class="active">全部</a></li>
                                            {foreach name="send_status" id="p" key="k"}
                                                <li item="send_status={$k}"><a>{$p}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">面单状态</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="send_status="><a class="active">全部</a></li>
                                            {foreach name="label_status" id="p" key="k"}
                                            <li item="label_url={$k}"><a>{$p}</a></li>
                                            {/foreach}
                                            {foreach name="print_status" id="p" key="k"}
                                            <li item="is_print={$k}"><a>{$p}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">发货时间</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="sent_time="><a class="active">全部</a></li>
                                            {foreach name="send_date" id="send" key="key"}
                                                <li item="send_date={$key}"><a>{$send}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                <div class="layui-form-item channel order-select">
                                    <label class="layui-form-label">排序方式</label>
                                    <div class="layui-input-block">
                                        <ul>
                                            <li item="sort="><a class="active">默认</a></li>
                                            {foreach name="sort" id="st" key="key"}
                                                <li item="sort={$key}"><a>{$st}</a></li>
                                            {/foreach}
                                        </ul>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">订单生成时间</label>
                                    <div class="layui-input-inline" style="width: 220px;">
                                        <input class="layui-input laydate-range" id="start_date" autocomplete="off" name="date" placeholder="录入时间">
                                    </div>
                                    <button type="button" class="layui-btn layui-btn layui-btn-normal search-btn"><i
                                            class="layui-icon layui-icon-search"></i></button>
                                </div>
                            </div>
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form">
                                    <div class="layui-col-md1 layui-row">
                                        <select id="select_order" lay-search lay-filter="select_order">
                                            {foreach name="select_order" id="item" key="key"}
                                                <option value="{$key}">{$item}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <div class="layui-col-md2 layui-row">
                                        <input id="order_name" placeholder="按回车搜索" class="layui-input"/>
                                    </div>
                                    <div class="layui-col-md1 layui-row">
                                        <select id="select_account" lay-search lay-filter="search">
                                            <option value="">销售账号</option>
                                            {foreach name="account" id="a"}
                                            <option value="{$a.account_id}">{$a.username ?: $a.store_name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <div class="layui-col-md1 layui-row">
                                        <select id="select_country" lay-search lay-filter="search">
                                            <option value="">国家</option>
                                            {foreach name="select_country" id="country"}
                                                <option value="{$country.code_two}">{$country.name_ch}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <div class="layui-col-md1 layui-row">
                                        <select id="select_logistics" lay-search lay-filter="search">
                                            <option value="">物流</option>
                                            {foreach name="select_logistics" id="logistics"}
                                                <option value="{$logistics.carrier_name}">{$logistics.carrier_name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <div class="layui-col-md2 layui-row">
                                        <a class="layui-btn layui-btn-normal order-select-down"><span>更多</span>&nbsp;&nbsp;<i
                                                class="fa fa-angle-double-down" aria-hidden="true"></i></a>
                                    </div>
                                    {php}if(isset($other_filter)):{/php}
                                        {foreach name="other_filter" id="filter" key="f"}
                                            <input type="hidden" class="other-filter" name="{$f}" value="{$filter}"/>
                                        {/foreach}
                                    {php}endif;{/php}
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-btn-group">
                        <button type="button" id="remove-all" class="layui-btn layui-btn-sm layui-btn-normal"><i
                                class="layui-icon layui-icon-delete"></i>批量删除
                        </button>
                        <a href="/attachment/template/order-template.xlsx?v=1"
                           class="layui-btn layui-btn-sm layui-btn-normal"><i
                                class="layui-icon layui-icon-download-circle"></i>下载模板</a>
                        <button type="button" id="import-order" class="layui-btn layui-btn-sm layui-btn-normal"><i
                                class="layui-icon layui-icon-upload-drag"></i>导入订单
                        </button>
                        <button type="button" id="export-order" class="layui-btn layui-btn-sm layui-btn-normal"><i
                                class="layui-icon layui-icon-export"></i>导出订单
                        </button>
                        <ul class="layui-nav layui-bg-green btnz"
                            style="font-size: 12px;border-radius: 0px;float: right;padding:0px;margin-left: 2px;">
                            <li class="layui-nav-item" style="line-height: 30px;font-size: 12px;">
                                <a class="layui-btn layui-btn-sm layui-btn-normal"
                                   style="color:white;font-size: 12px;padding: 0px 30px 0px 20px;">更多<span
                                        class="layui-nav-more" style="right: 10px;font-size: 12px;"></span></a>
                                <dl class="layui-nav-child" id="order-more-btn"> <!-- 二级菜单 -->
                                    <dd>
                                        <button type="button" id="batch-select-chanel"
                                                class="layui-btn layui-btn-sm layui-btn-normal">选择渠道
                                        </button>
                                    </dd>
                                    <dd>
                                        <button type="button" id="batch-edit-status"
                                                class="layui-btn layui-btn-sm layui-btn-normal">修改状态
                                        </button>
                                    </dd>
                                    <dd>
                                        <button type="button" id="batch-print"
                                                class="layui-btn layui-btn-sm layui-btn-normal">批量打印
                                        </button>
                                    </dd>
                                    <dd>
                                        <button type="button" id="batch-remark"
                                                class="layui-btn layui-btn-sm layui-btn-normal">批量备注
                                        </button>
                                    </dd>
                                </dl>
                            </li>
                        </ul>
                    </div>
                    <table class="layui-hide" id="commodity" lay-filter="commodity"></table>
                </div>
            </div>
        </div>
    </div>

    <!--操作-->
    <script type="text/html" id="operation">
        <div>
            <button style="margin-bottom: 3px;" lay-event="look" type="button" class="layui-btn layui-btn-sm"><i
                class="layui-icon layui-icon-search"></i></button>
            <br>
            <button style="margin-bottom: 3px;" lay-event="print" type="button"
                    class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon layui-icon-print"></i></button>
            <br>
            <button style="margin-bottom: 3px;" lay-event="edit" type="button"
                    class="layui-btn layui-btn-sm layui-btn-warm"><i class="layui-icon layui-icon-edit"></i></button>
            <br>
            <button type="button" lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger"><i
                    class="layui-icon layui-icon-delete"></i></button>
        </div>
    </script>
    <!-- 修改订单状态-->
    <script type="text/html" id="edit-order-status">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form-item channel order-status-select">
                        <label class="layui-form-label">订单状态</label>
                        <div class="layui-input-block">
                            <ul>
                                {foreach name="order_status" id="p" key="k"}
                                    <li item="order_status={$k}"><a>{$p}</a></li>
                                {/foreach}
                            </ul>
                        </div>
                    </div>
                    <div class="layui-form-item channel order-status-select">
                        <label class="layui-form-label">发货状态</label>
                        <div class="layui-input-block">
                            <ul>
                                {foreach name="send_status" id="p" key="k"}
                                    <li item="send_status={$k}"><a>{$p}</a></li>
                                {/foreach}
                            </ul>
                        </div>
                    </div>
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label">物流商</label>
                            <div class="layui-input-inline">
                                <select id="logistics_name" lay-filter="carrier" lay-search>
                                    <option value="">请选择</option>
                                    {foreach name="carrier" id="c"}
                                        <option value="{$c.carrier_id}">{$c.carrier_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <select id="channel_id" lay-search>
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </script>
{/block}
{block name="script"}
    <script type="text/javascript">
        layui.use(['form', 'laydate', 'table', 'upload', 'layer'], function () {
            var form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate
                , table = layui.table
                , upload = layui.upload;

            //展示已知数据
            table.render({
                elem: '#commodity'
                , page: true
                , url: '{:url("order/manager/index")}?' + $.param(getOtherFilter())
                //, toolbar: '#toolbarDemo'
                , title: '订单数据表'
                , height: 'full-200'
                , cols: [[ //标题栏
                    {type: 'checkbox'},
                    {
                        field: 'info', title: '商品信息', width: 360, templet: function (row) {
                            var html = "";
                            for (let i in row.detail) {
                                let line = row.detail[i];
                                html += `<div style="display: flex; margin-bottom: 10px;">
                                <div><a ${line.url ? 'target="_blank"' : ''} href="${line.url ? line.url : 'javascript:void(0)'}"><img src="${line.image}"></a></div>
                                <div style="margin-left: 10px;">
                                    <h3 style="color: #428bca;">${line.name}</h3>
                                    <div style="display: flex;flex-wrap: wrap">
                                        <p style="margin: 3px">币种：<span class="layui-badge layui-bg-green">${row.currcode?row.currcode.currency_name:row.currency}</span></p>
                                        <p style="margin: 3px">数量：<span class="layui-badge layui-bg-blue">${line.qty}</span></p>
                                        <p style="margin: 3px">属性：<span>${line.attr}</span></p>
                                        <p style="margin: 3px">SKU：<span class="layui-badge layui-bg-cyan">${line.sku}</span></p>
                                    </div>
                                </div>
                            </div>`;
                            }
                            return html;
                        }
                    }
                    ,{
                        field: "total_price", title: "总金额", templet:function (row) {
                            return `<p>${row.currcode?row.currcode.currency_name:row.currency}：${row.total_price}</p>
                                    <p>人民币：${row.total_price_rmb > 0 ? row.total_price_rmb : ''}</p>
                                    `;
                        }
                    }
                    , {
                        field: 'address', title: '收件人', templet: function (row) {
                            var s = row.consignee ? row.consignee : row.buyer_first_name + ' ' + row.buyer_last_name;
                            return `<p>收件人：${s}</p>
                                    <p>国家：${row.buyer_country ? row.buyer_country : row.buyer_country_code}</p>
                                    <!--<p>城市：${row.buyer_city ? row.buyer_city : ''}</p>-->
                                    <!--<p>地址：${row.buyer_address_1}</p>-->
                                    `;
                        }
                    }
                    , {
                        field: 'order_no', title: '订单号', templet: function (row) {
                            return `<div>
                                     <p>平台：${row.platform_name}</p>
                                     <p>平台订单号：${row.order_no}</p>
                                     <p>内部订单号：${row.order_sn}</p>
                                </div>`;
                        }
                    }
                    , {
                        field: 'date', title: '时间', templet: function (row) {
                            return `<div>
                                    <p>下单：${row.order_source_create_time ? row.order_source_create_time : ''}</p>
                                    <p>付款：${row.order_pay_time ? row.order_pay_time : ''}</p>
                                    <p>发货：${row.sent_time ? row.sent_time : ''}</p>
                                    <p>最迟发货时间：<span class="layui-badge">${row.latest_delivery_time ? row.latest_delivery_time.substr(0, 10) : ''}</span></p>
                                </div>`;
                        }
                    }
                    , {
                        field: 'method', title: '物流方式', templet: function (row) {
                            return `
                                <p style="margin: 3px">重量：<span class="layui-badge layui-bg-blue">${row.weight}克</span></p>
                                <p>物流商：${row.logistics_name ? row.logistics_name : row.shipping_method}</p>
                                <p>追踪号：${row.shipping_code}</p>
                                <p>是否生成：<span class="layui-badge">${row.label_url?'是':'否'}</span></p>
                                <p>是否打印：<span class="layui-badge layui-bg-green">${row.is_print}</span></p>
                                `;
                        }
                    }
                    , {
                        field: 'status', width: 150, title: '状态', templet: function (row) {
                            return `
                                <p style="margin: 5px; text-align: center;">订单：<span class="layui-badge">${row.order_status}</span></p>
                                <p style="margin: 5px; text-align: center;">发货：<span class="layui-badge layui-bg-cyan">${row.send_status}</span></p>
                                `;
                        }
                    }
                    , {field: 'platform_remark', title: '买家备注'}
                    , {field: 'remark', title: '备注', edit: 'text'}
                    , {field: 'experience', title: '操作', width: 70, fixed: "right", toolbar: '#operation'}
                ]]
                //,skin: 'line' //表格风格
                , even: true
                , limits: [100, 150, 300, 500]
                , limit: 100 //每页默认显示的数量
            });

            //监听单元格编辑
            table.on('edit(commodity)', function (obj) {
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                var params = {field, value};
                params["order_id"] = data.order_id;
                $.post("{:url('/order/manager/edit')}", params).done(function(response)
                {
                    var icon = response.code == 0 ? 6 : 5;
                    layer.msg(response.msg, {icon: icon, time: 1500});
                });
            });

            // 订单搜索
            $(".search-btn").click(function () {
                var $where = {};
                $("div.order-select li a.active").each(function (i, e) {
                    var item = $(e).parent().attr("item").split("=");
                    if (item[1]) $where[item[0]] = item[1];
                });
                var logistics = $("#select_logistics option:selected").val(),
                    country = $("#select_country option:selected").val(),
                    account = $("#select_account option:selected").val(),
                    orderVal = $("#order_name").val().trim(),
                    start_date = $("#start_date").val().trim();
                if (orderVal) $where[$("#select_order option:selected").val()] = orderVal;
                if (country) $where["buyer_country_code"] = country;
                if (account) $where["account_id"] = account;
                if (logistics) $where["logistics_name"] = logistics;
                if (start_date) $where["start_date"] = start_date;
                $where = $.extend($where, getOtherFilter());
                // if($.isEmptyObject($where)) return;
                var url = "{:url('/order/manager/index')}" + ($.isEmptyObject($where) ? "" : "?" + $.param($where));
                table.reload("commodity", {
                    url: url,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    // where: $where,
                    // done: function(){console.log(this.where);}
                });
            });
            // 监听搜索下拉框
            form.on('select(search)', function (data) {
                if (data.value != "") reloadOrderTable();
            });
            form.on('select(select_order)', function (data) {
                if ($("#order_name").val().trim() != "") reloadOrderTable();
            });

            // 监听输入框回车
            $("#order_name").keyup(function (event) {
                if (event.keyCode == 13) reloadOrderTable();
            });

            //监听行工具事件
            table.on('tool(commodity)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除订单？', function (index) {
                        deleteOrder(data.order_id, function () {
                            obj.del();
                            layer.close(index);
                        });
                    });
                } else if (obj.event === 'print') {
                    if (data.label_url.length < 1) {
                        layer.msg("未生成面单", {icon: 5, time: 1500});
                        return;
                    }
                    $.post("{:url('/order/manager/edit')}", {order_id: data.order_id, field: "is_print", value: 1});
                    window.open(data.label_url, "_blank");
                } else if (obj.event === 'edit') {
                    openEditOrderStatus(function(params)
                    {
                        params["order_id"] = data.order_id;
                        $.post("{:url('/order/manager/edit')}", params).done(function (response) {
                            var icon = response.code == 0 ? 6 : 5;
                            layer.msg(response.msg, {icon: icon, time: 1500});
                            //if(response.code == 0) reloadOrderTable();
                        });
                    });
                } else if (obj.event === 'look') {
                    layer.open({
                        type: 2,
                        title: '订单详情',
                        area: ['80%', '80%'],
                        content: '{:url("order/manager/look")}?order_id=' + data.order_id
                    });
                }
            });

            function getOtherFilter()
            {
                var other = {};
                $("input.other-filter").each(function()
                {
                    other[$(this).attr("name")] = $(this).val();
                });
                return other;
            }
            // 打开弹窗更新订单状态
            function openEditOrderStatus(fn)
            {
                layer.open({
                    title: '修改订单状态',
                    area: ['60%', '45%'],
                    content: $("#edit-order-status").html()
                    , success: function (layero, index) {
                        form.render('select');
                        form.on('select(carrier)', function(data)
                        {
                            if(!data.value) return false;
                            $.get("{:url('cha/channel/channelList')}", {carrier_id:data.value}).done(function(response)
                            {
                                if(response.code == 0)
                                {
                                    var data = response.data;
                                    var html = ["<option value=''>请选择</option>"];
                                    for(let i in data)
                                    {
                                        html.push("<option value='" + data[i].channel_id + "'>" + data[i].channel_name + "</option>");
                                    }
                                    $("#channel_id").html(html.join(""));
                                    form.render('select');
                                }
                            });
                        });
                    }
                    , yes: function (index, layero) {
                        var params = {
                            "field": [],
                            "value": []
                        };
                        $(".order-status-select .active").each(function () {
                            let t = $(this).parent().attr("item").split("=");
                            params.field.push(t[0]);
                            params.value.push(t[1]);
                        });
                        var logistics = $("#logistics_name option:selected").val(),
                            channel = $("#channel_id option:selected").val();
                        if(logistics && channel)
                        {
                            params.field.push("logistics_name");
                            params.value.push($("#logistics_name option:selected").text());
                            params.field.push("channel_id");
                            params.value.push(channel);
                        }
                        layer.close(index);
                        if(params.field.length < 1) return;
                        if(typeof fn === "function") fn(params);
                    }
                });
            }
            // 刷新表格订单
            function reloadOrderTable() {
                $(".search-btn").click();
                form.render('select');
            }

            /**
             * 删除订单
             * @param orderId  订单id 可多个
             * @param fn 回调函数
             */
            function deleteOrder(orderId, fn) {
                $.get("{:url('order/manager/delete')}", {ids: orderId}).done(function (response) {
                    var icon = response.code == 0 ? 6 : 5;
                    if(response.code == 0)
                    {
                        layer.msg(response.msg, {icon: icon, time: 1500}, fn ? fn : null);
                    }
                    else
                    {
                        layer.msg(response.msg, {icon: icon, time: 1500});
                    }
                });
            }

            // 导入订单
            upload.render({
                elem: '#import-order'
                , url: '{:url("file/upload",["type"=>"document"])}'
                , accept: 'file' //普通文件
                , exts: 'xlsx|xls|csv' // 指定类型
                , field: "file"
                , before: function (obj) {
                    layer.load(0, {shade: false});
                }
                , done: function (response, index, upload) {
                    if (response.code != 0) {
                        layer.closeAll('loading');
                        var icon = response.code == 0 ? 6 : 5;
                        layer.msg(response.msg, {icon: icon, time: 1500});
                        return;
                    }
                    $.post("{:url('order/manager/import')}", {"path": response.data.src}).done(function (res) {
                        layer.closeAll('loading');
                        var icon = 5, time = 5500;
                        if (res.code == 0) {
                            icon = 6;
                            time = 1500;
                        }
                        var icon = res.code == 0 ? 6 : 5;
                        layer.msg(res.msg.replace(/\n/g, "<br/>"), {icon, time}, function(){
                            if (res.code == 0) reloadOrderTable();
                        });
                    });
                }
                , error: function (index, upload) {
                    layer.msg('上传失败');
                }
            });

            // 导出订单
            $("#export-order").click(function () {
                var data = table.checkStatus("commodity").data;
                var ids = [];
                for (let i in data) ids.push(data[i].order_id);
                var start_date = $("#start_date").val().trim();
                if (!data.length && !start_date) return layer.msg('请选择要导出的订单');
                layer.load(0, {shade: false});
                $.get("{:url('order/manager/export')}", $.param({ids, start_date})).done(function (response) {
                    layer.closeAll('loading');
                    response.code == 0
                        ? location.href = "{:url('file/download')}?file=" + response.data.src
                        : layer.msg(response.msg, {icon: 5, time: 1500});
                });
            });

            // 批量删除订单
            $("#remove-all").click(function () {
                var data = table.checkStatus("commodity").data,
                    dataLen = data.length;
                if (!dataLen > 0) return layer.msg('请选择要删除的订单');
                layer.confirm(`你真的要删除【${dataLen}】个订单吗？`, {btn: ['确认删除', '取消']}, function (index) {
                    layer.close(index);
                    layer.load(0, {shade: false});
                    var ids = [];
                    for (let i in data) ids.push(data[i].order_id);
                    /*$("div.layui-table-body table tbody input[name='layTableCheckbox']:checked").each(function()
                    {
                        var n = $(this).parents("tbody tr").index();  // 获取checkbox所在行的顺序
                        $("div.layui-table-body table tbody ").find("tr:eq(" + n + ")").remove(); // 移除行
                        //如果是全选移除，就将全选CheckBox还原为未选中状态
                        $("div.layui-table-header table thead div.layui-unselect.layui-form-checkbox").removeClass("layui-form-checked");
                    });*/
                    deleteOrder(ids.join(","), function () {
                        reloadOrderTable();
                        layer.closeAll('loading');
                    });
                });
            });

            // 批量备注
            $("#batch-remark").click(function () {
                var data = table.checkStatus("commodity").data;
                if (data.length < 1) {
                    layer.msg("请选择要备注的订单");
                    return;
                }
                var ids = [];
                for (let i in data) ids.push(data[i].order_id);
                layer.prompt({title: '批量备注订单', formType: 2}, function (text, index) {
                    layer.close(index);
                    $.post("{:url('order/manager/edit')}", {
                        order_id: ids.join(","),
                        field: "remark",
                        value: text
                    }).done(function (response) {
                        var icon = response.code == 0 ? 6 : 5;
                        layer.msg(response.msg, {icon: icon, time: 1500});
                        reloadOrderTable();
                    });
                });
            });

            // 点击筛选订单状态
            $("body").on("click", ".order-status-select li", function () {
                var $this = $(this);
                $this.siblings().find("a").removeClass("active");
                $this.find("a").addClass("active");
            });

            // 修改订单状态
            $("#batch-edit-status").click(function () {
                var data = table.checkStatus("commodity").data;
                if (data.length < 1) {
                    layer.msg("请选择要修改的订单");
                    return;
                }
                openEditOrderStatus(function(params)
                {
                    var data = table.checkStatus("commodity").data,
                        ids = [];
                    for (let i in data) ids.push(data[i].order_id);
                    params["order_id"] = ids.join(',');
                    $.post("{:url('/order/manager/edit')}", params).done(function (response) {
                        var icon = response.code == 0 ? 6 : 5;
                        layer.msg(response.msg, {icon: icon, time: 1500});
                        reloadOrderTable();
                    });
                });
            });

            // 批量打印
            $("#batch-print").click(function () {
                var data = table.checkStatus("commodity").data;
                if (data.length < 1) {
                    layer.msg("请选择要打印的订单");
                    return;
                }
                var ids = [], labels = [];
                for (let i in data) {
                    if (data[i].label_url != "") {
                        ids.push(data[i].order_id);
                        labels.push(data[i].label_url);
                    }
                }
                if (ids.length < 1) {
                    layer.msg("未生成面单", {icon: 5, time: 1500});
                    return;
                }
                $.post("{:url('/order/manager/edit')}", {
                    order_id: ids,
                    field: "is_print",
                    value: 1
                }).done(function (response) {
                    if (response.code == 0) reloadOrderTable();
                });
                labels.forEach(e => {
                    window.open(e, "_blank");
                });
            });

            // 点击筛选
            $(".order-select li").click(function () {
                var $this = $(this);
                $this.siblings().find("a").removeClass("active");
                $this.find("a").addClass("active");
                reloadOrderTable();
            });

            // 展示更多筛选项
            $(".order-select-down").click(function () {
                var $this = $(this), $box = $(".screen-box");
                $box.toggle("fast");
                if ($box.data("c")) {
                    $box.data("c", 0);
                    $this.find("span").text("更多");
                    $this.find("i").removeClass("fa-angle-double-up").addClass("fa-angle-double-down");
                } else {
                    $box.data("c", 1);
                    $this.find("span").text("收起");
                    $this.find("i").removeClass("fa-angle-double-down").addClass("fa-angle-double-up");
                }
            });

            // 重置表格大小
            resetTableSize(table, "commodity");
        });
    </script>
{/block}
